import {defineStore} from "pinia";
import type {reqCategoryListType} from "@/api/category"
import {reqCategory1List,reqCategory2List,reqCategory3List} from "@/api/category";
interface stateType{
    category1List:reqCategoryListType,
    category2List:reqCategoryListType,
    category3List:reqCategoryListType,
    category1Id:null | number,
    category2Id:null | number,
    category3Id:null | number,
}

const useCategoryList = defineStore("category",{
    state:():stateType=>{
        return{
            category1List:[],
            category2List:[],
            category3List:[],
            category1Id:null,
            category2Id:null,
            category3Id:null,
        }
    },
    actions:{
        async getCategory1List(){
            try {
                const result =  await reqCategory1List()
                this.category1List = result
            }catch (e){
                return Promise.reject(e)
            }
        },
        async getCategory2List(){
            try {
                const result =  await reqCategory2List(this.category1Id as number)
                this.category1List = result
            }catch (e){
                return Promise.reject(e)
            }
        }, async getCategory3List(){
            try {
                const result =  await reqCategory3List(this.category1Id as number)
                this.category1List = result
            }catch (e){
                return Promise.reject(e)
            }
        }
    }
})

export default useCategoryList